<template>
    <el-dialog
      width="80%"
      v-model="visible"
      :before-close="beforeClose"
      append-to-body
      v-if="config"
    >
      <NvEntry :config="config" ref="nvEntry" @define-event="handleEvent($event)"></NvEntry>
      <span slot="footer" class="dialog-footer">
          <div style="display: flex; flex-direction: row; justify-content: flex-end; ">
          <el-button @click="cancelClose()">取消</el-button>
          <el-button type="primary"  @click="confirmClose()">确认</el-button>
          </div>
      </span>
    </el-dialog>
</template>

<script>
import { ref, getCurrentInstance, defineAsyncComponent } from 'vue'
export default {
  name: 'NvEntryDialog',
  components: {
    NvEntry: defineAsyncComponent(() => import('@/views/basic/NvEntry.vue'))
  },
  setup(props) {
    const currentInstance = getCurrentInstance();
    const visible = ref(false);
    const config = ref({});
    const chooseCb = ref(null);
    function showDialog(aConfig, callback) {
      config.value = aConfig;
      chooseCb.value = callback;
      visible.value = true;
    }
    function confirmClose() {
      const nvs = currentInstance.refs.nvEntry.getNvs();
      chooseCb.value(nvs);
      visible.value = false;
    }
    return {
      visible,
      config,
      showDialog,
      chooseCb,
      confirmClose
    }
  },
  methods: {
    beforeClose(next) {
      this.config = null;
      this.chooseCb = null;
      next();
    },
    cancelClose() {
      this.visible = false;
    },
    handleEvent(event) {
    }
  }
}
</script>

<style scoped>

</style>
